using CassiniDev;
using FluentAssertions;
using TripleA.Core.Extensions.Web;
using TripleA.Core.Interfaces.Entities;
using TripleA.StoryQ;

namespace TripleA.Tests.Web
{
    public class WebDomain : StoryQTestDomain<WebContext>
    {
        private HttpStepConfig _request;
        private readonly Server _webserver;

        public WebDomain()
        {
            _webserver = new Server(81, "web");
            _webserver.Start();
        }

        public override void Dispose()
        {
            if (_webserver == null) return;

            _webserver.ShutDown();
            _webserver.Dispose();
        }

        public void TheRequest(HttpStepConfig request)
        {
            _request = request;
        }

        public void TheRequestIsMade()
        {
            TripleA.CallUri(_request);
        }

        public void TheRequestQuerystringShouldBe_(string expected)
        {
            Context.Response.Uri.Query.Should().Be(expected);
        }

        public void TheRequestPathShouldBe_(string expected)
        {
            Context.Response.Uri.PathAndQuery.StartsWith(expected).Should().BeTrue();
        }
    }
}